<template>
  <div class="test">
    <div class="select">
       <el-select v-model="value" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
  </el-select>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
import dayjs from "dayjs";
// export const getDownFile = (res?, name?, isALLFile?) => {
//   let blob: any;
//   let fileName = "";
//   if (res instanceof Blob) {
//     blob = new Blob([res]);
//     if (isALLFile && name) {
//       fileName = name;
//     } else {
//       if (name) {
//         fileName = `${name}.xlsx`;
//       } else {
//         fileName = `${dayjs().format("YYYY-MM-DD HH_mm_ss")}.xlsx`;
//       }
//     }
//   } else {
//     blob = new Blob([res.data]);
//     // 从响应头中获取文件名称
//     let fileNameResponse: any;
//     const contentDisposition = res.headers["content-disposition"];
//     if (contentDisposition) {
//       // 正则获取filename的值
//       const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
//       const matches = filenameRegex.exec(contentDisposition);
//       if (matches != null && matches[1]) {
//         fileNameResponse = matches[1].replace(/['"]/g, "");
//         // 通过 URLEncoder.encode(pFileName, StandardCharsets.UTF_8.name()) 加密编码的, 使用decodeURI(fileName) 解密
//         fileNameResponse = decodeURI(fileNameResponse);
//         // 通过 new String(pFileName.getBytes(), StandardCharsets.ISO_8859_1) 加密编码的, 使用decodeURI(escape(fileName)) 解密
//         // fileName = decodeURI(escape(fileName))
//       }
//       fileName = fileNameResponse;
//       console.log(fileNameResponse);
//     } else {
//       if (name) {
//         fileName = `${name}.xlsx`;
//       } else {
//         fileName = `${dayjs().format("YYYY-MM-DD HH_mm_ss")}.xlsx`;
//       }
//     }
//   }

 export default {
    data() {
      return {
        options: [{
          value: '1',
          label: '导出本表'
        }, {
          value: '2',
          label: '导出全部'
        }],
        value: '1'
      }
    },
    methods:{
     async getDomwBlobFile(name,){
       let res = await axios({
          url:'http://192.168.8.232:8002/res/data/getResTemplate',
          method:'get'
        })
        console.log(res?.data);
          // 下载文件
          let blob;
          let fileName = "";
          if (res instanceof Blob) {
            blob = new Blob([res]);
            if (isALLFile && name) {
              fileName = name;
            } else {
              if (name) {
                fileName = `${name}.xlsx`;
              } else {
                fileName = `${dayjs().format("YYYY-MM-DD HH_mm_ss")}.xlsx`;
              }
            }
          } else {
            blob = new Blob([res.data]);
            // 从响应头中获取文件名称
            let fileNameResponse;
            const contentDisposition = res.headers["content-disposition"];
            if (contentDisposition) {
              // 正则获取filename的值
              const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
              const matches = filenameRegex.exec(contentDisposition);
              if (matches != null && matches[1]) {
                fileNameResponse = matches[1].replace(/['"]/g, "");
                // 通过 URLEncoder.encode(pFileName, StandardCharsets.UTF_8.name()) 加密编码的, 使用decodeURI(fileName) 解密
                fileNameResponse = decodeURI(fileNameResponse);
                // 通过 new String(pFileName.getBytes(), StandardCharsets.ISO_8859_1) 加密编码的, 使用decodeURI(escape(fileName)) 解密
                // fileName = decodeURI(escape(fileName))
              }
              fileName = fileNameResponse;
              console.log(fileNameResponse);
            } else {
              if (name) {
                fileName = `${name}.xlsx`;
              } else {
                fileName = `${dayjs().format("YYYY-MM-DD HH_mm_ss")}.xlsx`;
              }
            }



  
      }
  
    },
    created(){
      this.getDomwFile();
    }
  }
</script>

<style  scoped>
 .select {
  display: flex;
  justify-content:center;
  align-items: center;
  height: 60px;
  }
</style>
